package com.ydcycloud.job.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.smart.mvc.dao.hibernate.JdbcDao;
import com.smart.mvc.model.Pagination;
import com.ydcycloud.company.model.Trade;
import com.ydcycloud.job.dao.JobDao;
import com.ydcycloud.job.model.ComProfession;
import com.ydcycloud.job.model.Profession;
import com.ydcycloud.sys.dao.impl.BaseDaoImpl;

@Component("jobDao")
public class JobDaoImpl  extends BaseDaoImpl<ComProfession, Integer> implements JobDao {

	@Resource
	private JdbcDao baseJdbcDao;

	@Override
	public Pagination<Map<String, Object>> findJob(Integer pageNo,
			Integer pageSize, Integer areaCode, String jobName,
			String profession, String sortType, Integer companyId) {
		
		StringBuffer sql = new StringBuffer();
		List<Object> params = new ArrayList<Object>(); 
		sql.append("SELECT a.id,a.expTime,a.salary,a.personCount,a.create_date AS createDate,b.companyName,b.addressDetail,c.profession,a.jobName,a.education "
				+ "FROM t_com_profession a "
				+ "LEFT JOIN t_company b ON a.companyId=b.id "
				+ "LEFT JOIN t_profession c ON c.id=a.professionId where 1=1");
			
		if(areaCode != null){
			sql.append(" and b.address like '%"+areaCode+"%' ");
		}
		if(jobName != null){
			sql.append(" and a.jobName like '%"+jobName+"%' ");
		}
		if(profession != null){
			sql.append(" and c.profession = '"+profession+"'");
		}
		if(sortType != null){
//			sql.append(" and c.profession = "+profession+"");
		}
		if(companyId != null){
			sql.append(" and a.companyId = '"+companyId+"'");
		}
		sql.append(" order by a.create_date desc ");
		System.out.println(sql.toString());
		Pagination<Map<String,Object>> p = new Pagination<Map<String,Object>>(pageNo,pageSize);
		baseJdbcDao.pageSqlMapQuery(p, sql.toString(), params.toArray());
		
		return p;
	}

	@Override
	public Map<String, Object> getDetail(Integer jobId) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT a.jobName,b.profession,a.expTime,a.education,a.endDate,a.personCount,a.salary,a.introduce,a.requirement "
				+ "FROM t_com_profession a LEFT JOIN t_profession b ON a.professionId=b.id WHERE a.id="+jobId+"");
		
		Map<String, Object> list = baseJdbcDao.findSqlMapQueryFirst(sql
				.toString());
		return list;
	}

	@Override
	public List<Profession> findProfessionName() {
		String sql = "SELECT id,profession FROM t_profession ";
		return findListBySql(Profession.class, sql);
	}

	
}
